#include <SharpShooter.h>
#include "TankFactory.h"
#include "TankBase.h"
#include "Terrain.h"

CTankFactory::CTankFactory(CSceneManager *smgr)
:m_SceneManager(smgr)
{
  iniFactory();
}

void CTankFactory::iniFactory()
{
  IMesh *mesh = m_SceneManager->createMesh(TANK1_MESH_PATH,MESH_TYPE_MD2);
  m_MeshList.insert(pair<TANK_TYPE,IMesh*>(TANK_TYPE1,mesh));

  TexturePtr texP = m_SceneManager->createTexture(TANK1_TEXTURE_PATH);
  m_TexutreList.insert(pair<TANK_TYPE,TexturePtr>(TANK_TYPE1,texP));
}

CTankBase * CTankFactory::createTank(float x, float y, TANK_TYPE type)
{
  CMeshSceneNode *msd = m_SceneManager->addMeshSceneNode(m_MeshList[type],
  m_SceneManager->getRootNode(),Vector3f(x,0.0,y),Vector3f::ZERO,Vector3f(BOX_SCALE*4,BOX_SCALE + BOX_SCALE,BOX_SCALE*4));
  msd->setTexture(m_TexutreList[type]);
  //msd->setEffect("phong");
  CTankBase *tank = new CTankBase(x,y,msd,TANK_DIR_FORWARD,1);
  m_TankList.push_back(tank);
  return tank;
}

CTankFactory::~CTankFactory()
{
  list<CTankBase*>::iterator iter= m_TankList.begin();
  for (; iter != m_TankList.end(); iter++)
  {
    delete *iter;
  }
}